home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Utilities / Miscellaneous / CopyPaste 3.3.4 / CopyPaste Tools Sourcecode / Selection Sort.c / BubbleSort.c next >
Encoding:
C/C++ Source or Header  |  1989-11-18  |  871 b   |  34 lines  |  [TEXT/KAHL]

  1. #include "ToolSort.h"
  2. /*=========================================================================
  3. Module:        bubble
  4.  
  5. Purpose:    Sort array in ascending order.  
  6.  
  7. Notes:        Sorts and array in increasing order.  This algorithm has a 
  8.             complexity of n^2.
  9.  
  10. Uses:        Function Comp( *type, *type) and function Swap( *type, *type).
  11.  
  12. Returns:    selLine
  13.  
  14. =========================================================================*/
  15. Bubble(elem, big, num, comp, swap) 
  16.     void    *elem;            /* Array of elem pointers*/
  17.     int        big;            /* size of the data elements */
  18.     int        num;            /* No. elem*/
  19.     int     (*comp)();        /* pointer to comparison function */
  20.     int        (*swap)();        /* pointer to swap function */
  21.     {
  22.     register char    *b = elem;
  23.     register int    k,i;
  24.         
  25.     for (k=1; k<=num-1; k++)
  26.         {
  27.         for (i=0; i<num-k; i++)
  28.             {
  29.             if ( (*comp)(b+i*big, b+(i+1)*big) > 0)
  30.                 (*swap)(b+i*big, b+(i+1)*big);
  31.             }
  32.         }
  33.     }
  34.